<template>
  <div class="app-container">
    <div class="head-container">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="咨询人">
          <el-input v-model="searchForm.quizzer" placeholder="咨询人" />
        </el-form-item>
        <el-form-item label="咨询内容">
          <el-input
            v-model="searchForm.context"
            placeholder="咨询内容"
          />
        </el-form-item>
        <el-form-item label="回复律师">
          <el-input
            v-model="searchForm.replyName"
            placeholder="回复律师"
          />
        </el-form-item>
        <el-form-item label="回复状态">
          <el-select v-model="searchForm.replyStatus" placeholder="活动区域">
            <el-option label="全部" value="" />
            <el-option label="已回复" value="1" />
            <el-option label="未回复" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="findDispatchList">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--表格渲染-->
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" label="序号" :index="indexMethod" align="center" />
      <el-table-column v-if="false" prop="id" label="ID" width="250" header-align="center" />
<!--      <el-table-column prop="title" label="标题" width="150" header-align="center" show-overflow-tooltip />-->
      <el-table-column prop="context" label="内容" header-align="center" show-overflow-tooltip />
      <el-table-column prop="questionType" label="类型" width="150" align="center" />
      <el-table-column prop="quizzer" label="咨询人" width="150" align="center" />
      <el-table-column prop="qtime" label="咨询时间" width="150" align="center" />
      <el-table-column prop="dtime" label="指派时间" width="150" align="center" />
      <el-table-column v-if="false" prop="replyid" label="指派给的律师ID" width="50" align="center" />
      <el-table-column prop="replyName" label="回复律师" align="center" width="150" />
      <el-table-column
        label="回复状态"
        width="150"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button v-if="scope.row.answerId" type="success" plain size="mini" @click="handleQueryAnswerById(scope.row.answerId)">已回复</el-button>
          <el-button v-else size="mini" type="info" plain disabled>未回复</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :current-page="pagination.currentPage"
      :page-sizes="[30, 50, 300, 400]"
      :page-size="pagination.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

    <!--查看回复内容-->
    <el-dialog
      title="回复内容"
      :visible.sync="dialogVisible"
      width="30%"
      class="reply-content"
    >
      <p>{{ answer.solution }}</p>
      <div><span style="margin-right:15px">回复人：{{ answer.reply }} </span>时间：{{ answer.cTime }}</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { findDispatch } from '@/api/law/dispatch'
import { queryAnswerById } from '@/api/law/answer'
export default {
  components: {
  },
  data() {
    return {
      dialogVisible: false,
      answer: {
        reply: '',
        solution: '',
        cTime: ''
      },
      searchForm: {
        quizzer: '',
        replyName: '',
        context: '',
        replyStatus: '',
        isMy: false
      },
      tableData: [],
      pagination: {
        currentPage: 1,
        pageSize: 30,
        total: 0
      }
    }
  },
  created() {
    this.findDispatchList()
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    },
    findDispatchList() {
      const pagination = {
        currentPage: this.pagination.currentPage,
        pageSize: this.pagination.pageSize
      }
      const queryParam = { ...this.searchForm, ...pagination }
      findDispatch(queryParam).then((res) => {
        this.tableData = res.records
        this.pagination.total = res.total
      }).catch((err) => {
        console.log(err)
      })
    },
    handleQueryAnswerById(answerId) {
      console.log('row', answerId)
      const parma = {
        id: answerId
      }
      queryAnswerById(parma).then((res) => {
        console.log('回复内容', res)
        // {
        //   "cTime":"2021-01-26 18:26:28",
        //   "id":"1",
        //   "orderSn":1,
        //   "questionId":"1",
        //   "reply":"王国强",
        //   "solution":"不需要，侵权责任由雇主承担。",
        //   "uTime":"2021-01-26 18:26:31"
        // }
        this.answer = { ...res }
        console.log('this.answer', this.answer)
      })
      this.dialogVisible = true
    },
    // 表格序号
    indexMethod(index) {
      return index + 1
    },
    // 改变分页大小
    handleSizeChange(val) {
      this.pagination.pageSize = val
    },
    // 改变页码
    handleCurrentChange(val) {
      this.pagination.currentPage = val
    }
  }
}
</script>

<style>
.reply-content{
  width: 100%;
  height: auto;
}
.reply-content .el-dialog__body{
  border-radius: 5px;
  margin: 0 5% 15px;
  padding: 0;
  width: 90%;
  color: #666;

}
.reply-content .el-dialog__body p:first-child{
  border-bottom: 1px dashed #ccc;
  padding-bottom: 8px;
  margin-bottom: 5px;
}
.reply-content .el-dialog__body div{
  text-align: right;
  color: #b7b6a5;
}
</style>
